package top.fengyulou.xiaofeng.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.fengyulou.xiaofeng.domain.UserExamPaper;
import top.fengyulou.xiaofeng.dto.ExamPaperDto;
import top.fengyulou.xiaofeng.dto.UserExamPaperDto;
import top.fengyulou.xiaofeng.mapper.UserExamPaperMapper;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author guochao
 * @version 1.0
 * @date 2022/3/16 15:29
 */
@Service
public class UserExamPaperService {
    @Resource
    private UserExamPaperMapper userExamPaperMapper;
    @Resource
    private ExamPaperService examPaperService;

    public void updateScore(UserExamPaperDto userExamPaperDto) {
        userExamPaperDto.setUpdateTime(new Date());
        userExamPaperDto.setLastUpdateUserId(userExamPaperDto.getCurrentUserId());
        userExamPaperMapper.updateScore(userExamPaperDto);
    }

    public void update(UserExamPaper userExamPaper) {
        userExamPaper.setUpdateTime(new Date());
        userExamPaper.setLastUpdateUserId(userExamPaper.getCurrentUserId());
        userExamPaperMapper.update(userExamPaper);
    }

    public UserExamPaperDto getById(String id){
        return userExamPaperMapper.getById(id);
    }

    //修改阅卷状态
    @Transactional
    public void updateMarkingStatus(UserExamPaperDto userExamPaperDto) {
        userExamPaperDto.setUpdateTime(new Date());
        userExamPaperDto.setLastUpdateUserId(userExamPaperDto.getCurrentUserId());
        userExamPaperMapper.updateMarkingStatus(userExamPaperDto);
        //修改阅卷数量
        ExamPaperDto examPaperDto = new ExamPaperDto();
        examPaperDto.setExamId(userExamPaperDto.getExamId());
        examPaperDto.setPaperId(userExamPaperDto.getPaperId());
        examPaperDto.setLastUpdateUserId(userExamPaperDto.getCurrentUserId());
        examPaperService.updateMarkingNum(examPaperDto);
    }
}
